package com.cloudsigns.factorymanager2.engineering.presenter;

import com.cloudsigns.factorymanager2.engineering.IView.ILoginView;
import com.cloudsigns.factorymanager2.engineering.bean.AccountInfoBean;
import com.cloudsigns.factorymanager2.engineering.model.ILoginModel;
import com.cloudsigns.factorymanager2.engineering.model.LoginModel;

import java.util.logging.Handler;

/**
 * Created by tony on 2018/1/14.
 */

public class LoginPresenter {
    private ILoginView view;
    private ILoginModel model;
    private android.os.Handler mHandler = new android.os.Handler();

    public LoginPresenter(ILoginView view) {
        this.view = view;
        this.model = new LoginModel();
    }

    public void login() {


        model.login(view.getUserName(), view.getPassword(), new LoginModel.OnLoginListener() {
            @Override
            public void loginSuccess() {
                //需要在UI线程执行
                mHandler.post(new Runnable() {
                    @Override
                    public void run() {
                        view.toMainActivity();
                        view.hideLoading();
                    }
                });
            }

            @Override
            public void loginFailed(final String desc) {
                //需要在UI线程执行
                mHandler.post(new Runnable() {
                    @Override
                    public void run() {
                        view.showFailedError(desc);
                        view.hideLoading();
                    }
                });
            }
        });

    }


}
